cmake_minimum_required(VERSION 2.8.8 FATAL_ERROR)
if (POLICY CMP0057)
  cmake_policy(SET CMP0057 NEW)
endif()

PROJECT(WikiExamples)

if (Module_WikiExamples)
  message(STATUS "VTKWikiExamples: Building VTKWikiExamples as a Remote VTK Module")
  message(STATUS "VTKWikiExamples: All executables will have a \"wiki\" prefix")
  set(WIKI wiki)
  vtk_module_impl()
  if(NOT EXISTS "${VTK_BINARY_DIR}/VTKConfig.cmake")
    return()
  endif()
  find_package(VTK PATHS ${VTK_BINARY_DIR})
  include(${VTK_USE_FILE})
else()
  message(STATUS "VTKWikiExamples: Building VTKWikiExamples stand-alone")
# See if VTK is using OpenGL or OpenGL2
  find_package(VTK CONFIG)
  if (NOT VTK_RENDERING_BACKEND)
    set(VTK_RENDERING_BACKEND OpenGL)
  endif()
  find_package(VTK REQUIRED)
  include(${VTK_USE_FILE})
endif()
set(WikiExamples_TEST_LABELS "foo")
message(STATUS "VTKWikiExamples: VTK VERSION: ${VTK_VERSION}(${VTK_RENDERING_BACKEND})")

set(CMAKE_MODULE_PATH ${WikiExamples_SOURCE_DIR}/CMake ${CMAKE_MODULE_PATH})

option(BUILD_TESTING "Build the testing tree." OFF)
if (BUILD_TESTING)
  ENABLE_TESTING()
  INCLUDE(CTest)
  CONFIGURE_FILE(
    ${WikiExamples_SOURCE_DIR}/CMake/SampleBuildTest.cmake.in
    ${WikiExamples_BINARY_DIR}/SampleBuildTest.cmake @ONLY)
  message(STATUS "VTKWikiExamples: Tests will be built with label \"WikiExamples\"")
else()
  message(STATUS "VTKWikiExamples: Tests will not be built")
endif ()

include(PlatformSpecificChecks)

include(WikiPolicies)
# Set the CMake Policies
WikiPolicies()

#
# Mac specific
IF(APPLE)
  SET(EXECUTABLE_FLAG MACOSX_BUNDLE)
ENDIF(APPLE)

#-----------------------------------------------------------------------------
# Output directories.
if(NOT Module_WikiExamples)
  IF(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
    SET (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${WikiExamples_BINARY_DIR}/bin CACHE INTERNAL "Single output directory for building all libraries.")
  ENDIF(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
  IF(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
    SET (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${WikiExamples_BINARY_DIR}/bin CACHE INTERNAL "Single output directory for building all executables.")
  ENDIF(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
  MARK_AS_ADVANCED(CMAKE_LIBRARY_OUTPUT_DIRECTORY CMAKE_RUNTIME_OUTPUT_DIRECTORY)
else()
    SET (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${VTK_BINARY_DIR}/bin)
endif()
message(STATUS "VTKWikiExamples: Example executables are stored in ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")

ADD_SUBDIRECTORY(Cxx/Animation)
ADD_SUBDIRECTORY(Cxx/CompositeData)
IF(VTK_USE_MYSQL)
  ADD_SUBDIRECTORY(Cxx/Databases)
ENDIF(VTK_USE_MYSQL)
ADD_SUBDIRECTORY(Cxx/DataStructures)
if(${VTK_VERSION} VERSION_GREATER "6.10")
  ADD_SUBDIRECTORY(Cxx/Developers)
endif()
ADD_SUBDIRECTORY(Cxx/Filtering)
ADD_SUBDIRECTORY(Cxx/GeometricObjects)
IF(VTK_USE_INFOVIS)
  IF(VTK_USE_BOOST)
    ADD_SUBDIRECTORY(Cxx/Graphs)
  ENDIF(VTK_USE_BOOST)
ENDIF(VTK_USE_INFOVIS)
ADD_SUBDIRECTORY(Cxx/ImageData)
  ADD_SUBDIRECTORY(Cxx/Geovis)
ADD_SUBDIRECTORY(Cxx/Images)
ADD_SUBDIRECTORY(Cxx/ImplicitFunctions)
ADD_SUBDIRECTORY(Cxx/InfoVis)
ADD_SUBDIRECTORY(Cxx/Interaction)
ADD_SUBDIRECTORY(Cxx/IO)
ADD_SUBDIRECTORY(Cxx/Lighting)
ADD_SUBDIRECTORY(Cxx/Math)
ADD_SUBDIRECTORY(Cxx/Medical)
ADD_SUBDIRECTORY(Cxx/Meshes)
ADD_SUBDIRECTORY(Cxx/Modelling)
IF(VTK_USE_PARALLEL)
  ADD_SUBDIRECTORY(Cxx/Parallel)
ENDIF(VTK_USE_PARALLEL)
ADD_SUBDIRECTORY(Cxx/Picking)
ADD_SUBDIRECTORY(Cxx/Plotting)
ADD_SUBDIRECTORY(Cxx/PolyData)
ADD_SUBDIRECTORY(Cxx/Points)
ADD_SUBDIRECTORY(Cxx/RectilinearGrid)
ADD_SUBDIRECTORY(Cxx/Remote)
ADD_SUBDIRECTORY(Cxx/Rendering)
ADD_SUBDIRECTORY(Cxx/RenderMan)
ADD_SUBDIRECTORY(Cxx/SimpleOperations)
ADD_SUBDIRECTORY(Cxx/StructuredGrid)
IF(VTK_USE_TEXT_ANALYSIS)
  ADD_SUBDIRECTORY(Cxx/TextAnalysis)
ENDIF(VTK_USE_TEXT_ANALYSIS)
ADD_SUBDIRECTORY(Cxx/Texture)
ADD_SUBDIRECTORY(Cxx/Utilities)
ADD_SUBDIRECTORY(Cxx/Video)
IF(VTK_USE_VIEWS)
  ADD_SUBDIRECTORY(Cxx/Views)
ENDIF(VTK_USE_VIEWS)
ADD_SUBDIRECTORY(Cxx/Visualization)
ADD_SUBDIRECTORY(Cxx/VisualizationAlgorithms)
ADD_SUBDIRECTORY(Cxx/VolumeRendering)
ADD_SUBDIRECTORY(Cxx/Widgets)

# ADD_SUBDIRECTORY(Python/GeometricObjects)

if(vtkGUISupportQt_LOADED)
  message(STATUS "VTKWikiExamples: Building Qt examples")
  if(${VTK_VERSION} VERSION_GREATER "6" AND VTK_QT_VERSION VERSION_GREATER "4")
    # Instruct CMake to run moc automatically when needed.
    set(CMAKE_AUTOMOC ON)
    # We have ui files, this will bring in the macro: qt5_wrap_ui
    find_package(Qt5Widgets REQUIRED QUIET)
  else()
    FIND_PACKAGE(Qt4 REQUIRED)
    INCLUDE(${QT_USE_FILE})
  endif()
  ADD_SUBDIRECTORY(Cxx/Qt)
else()
  message(STATUS "VTKWikiExamples: Not building Qt examples")
endif()

OPTION(RUN_ADMIN_TESTS "Run the admin tests" OFF)
IF( BUILD_TESTING AND RUN_ADMIN_TESTS )
  ADD_TEST(CheckPagesForImages ${WikiExamples_SOURCE_DIR}/Admin/CheckPagesForImages)
  SET_TESTS_PROPERTIES(CheckPagesForImages PROPERTIES TIMEOUT 2000)
ENDIF()
